# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     job_welfare
   Description :
   Author :       Flyoung
   date：          2023/9/5
-------------------------------------------------
   Change Activity:
                   2023/9/5:
-------------------------------------------------
"""
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

from db.common import with_session

Base = declarative_base()


class JobWelfare(Base):
    __tablename__ = 'job_welfare'

    job_welfare = Column(Integer, primary_key=True, autoincrement=True)
    job_id = Column(Integer)
    welfare_id = Column(Integer)

    def __init__(self, job_id, welfare_id):
        self.job_id = job_id
        self.welfare_id = welfare_id

    def to_dict(self):
        return {
            'job_welfare': self.job_welfare,
            'job_id': self.job_id,
            'welfare_id': self.welfare_id
        }


@with_session
def add_job_welfare(session: Session, job_id, welfare_id):
    jw = JobWelfare(job_id=job_id, welfare_id=welfare_id)
    session.add(jw)
    return jw.to_dict()
